

package com.teaching.controller;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.teaching.common.Result;

import com.teaching.dto.CourseReplyDTO;
import com.teaching.entity.CourseReply;
import com.teaching.mapper.CourseReplyMapper;
import com.teaching.service.CourseReplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * 课件答复表
 *
 * @author xubb
 * @date 2021-03-22 15:28:52
 */
@RestController
@AllArgsConstructor
@RequestMapping("/courseReply" )
@Api(value = "courseReply", tags = "课件答复表管理")
public class CourseReplyController {
    @Resource
    private CourseReplyService courseReplyService;

    @Resource
    private CourseReplyMapper courseReplyMapper;

    /**
     * 分页查询
     *
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @PostMapping("/getCourseReplyList")
    public Result<IPage<CourseReply>> getCourseReplyList(@RequestBody CourseReplyDTO dto) {
        Page<CourseReply> page = new Page<>(dto.getPageNo(), dto.getPageSize());
        CourseReply courseReply = new CourseReply();
        BeanUtil.copyProperties(dto,courseReply);
        return Result.success(courseReplyMapper.getCourseReplyList(page, courseReply));
    }


    /**
     * 通过id查询
     *
     * @return R
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @PostMapping("/getCourseReplyInfo")
    public Result getCourseReplyInfo(@RequestBody CourseReply courseReply) {
        return Result.success(courseReplyService.getById(courseReply.getId()));
    }

    /**
     * 新增
     *
     * @param courseReply
     * @return R
     */
    @ApiOperation(value = "新增", notes = "新增")
    @PostMapping("/save")
    public Result save(@RequestBody CourseReply courseReply) {

        return Result.success(courseReplyService.save(courseReply));
    }

    /**
     * 修改
     *
     * @param courseReply
     * @return R
     */
    @ApiOperation(value = "修改", notes = "修改")
    @PostMapping("/updateById")
    public Result updateById(@RequestBody CourseReply courseReply) {

        return Result.success(courseReplyService.updateById(courseReply));
    }

    /**
     * 通过id删除
     *
     * @return R
     */
    @ApiOperation(value = "通过id删除", notes = "通过id删除")
    @PostMapping("/removeById")
    public Result removeById(@RequestBody CourseReply courseReply) {
        return Result.success(courseReplyService.removeById(courseReply.getId()));
    }

}
